package proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyClient {
    public static void main(String[] args) {
        //JDK实现的动态代理是基于接口的 要求代理的对象必须实现接口  implements Star
        //RealStar.class.getClassLoader()
//        Proxy.newProxyInstance()
        Star  proxy =(Star) Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), RealStar.class.getInterfaces(), new InvocationHandler() {
            RealStar realStar = new RealStar();
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//                System.out.println(method.getName());
                if(method.getName().equals("sing")){
                    System.out.println("所有方法执行前都要来我这里走一遍(❁´◡`❁)");
                    System.out.println("代理对象要面谈，签合同(*/ω＼*)");
                    realStar.sing();
                    System.out.println("代理对象收尾款！！！☆*: .｡. o(≧▽≦)o .｡.:*☆");
                }
                return null;
            }
        });
        System.out.println(proxy.getClass());
        System.out.println("-------------------------------------------------------------------------------");
//        proxy.sing();
        proxy.dance();
    }
}
